Numpy


In [20]:
import numpy as np
b = np.array([(1,2), (2, 1)])

print(b)
print()
print(2*b)
print()
print(b*b)
print()
print(b**2)
print()
print(1/b)  # Warning!


[[1 2]
 [2 1]]

[[2 4]
 [4 2]]

[[1 4]
 [4 1]]

[[1 4]
 [4 1]]

[[ 1.   0.5]
 [ 0.5  1. ]]

In [21]:
a = np.array([1, 2, 3])
b = np.array([2, 3, 4])
a * b, a.dot(b)


Out[21]:
(array([ 2,  6, 12]), 20)

In [29]:
A = np.matrix([
    [1, 2], 
    [2, 1]
])

w, v = np.linalg.eig(A)
print(w)  # Eigenvalues
print(v)  # Eingenvector
A


[ 3. -1.]
[[ 0.70710678 -0.70710678]
 [ 0.70710678  0.70710678]]
Out[29]:
matrix([[1, 2],
        [2, 1]])

Pandas


In [4]:
import pandas as pd

In [5]:
df = pd.read_csv("./auxFiles/pandasExample.csv")

In [6]:
df.head()


Out[6]:
Stores Code x y Group Region
0 Bayswater Bay -37.825908 145.279284 East East
1 Box Hill Box -37.831194 145.131673 East East
2 Croydon Cro -37.766767 145.303188 East East
3 Nunawading Nun -37.819239 145.166277 East East
4 Scoresby Sco -37.895472 145.241515 East East

In [7]:
df.shape


Out[7]:
(41, 6)

In [8]:
df.columns


Out[8]:
Index(['Stores', 'Code', 'x', 'y', 'Group', 'Region'], dtype='object')

In [9]:
df.dtypes


Out[9]:
Stores     object
Code       object
x         float64
y         float64
Group      object
Region     object
dtype: object

In [10]:
xDf = df['x']
yDf = df['y']

Matplotlib


In [67]:
import matplotlib.pyplot as plt

%matplotlib inline

rcParams["figure.figsize"] = [12.0, 6.0]

In [68]:
x = numpy.linspace(0, 2*numpy.pi, 50)
y1 = numpy.sin(x)
y2 = numpy.sin(2*x)

plot(x, y1)


Out[68]:
[<matplotlib.lines.Line2D at 0x7faa817d50b8>]

In [69]:
plot(x, y1, x, y2)


Out[69]:
[<matplotlib.lines.Line2D at 0x7faa81798550>,
 <matplotlib.lines.Line2D at 0x7faa81798c88>]

In [70]:
scatter(x, y1)


Out[70]:
<matplotlib.collections.PathCollection at 0x7faa816dea58>

In [71]:
hist(rand(1000), 10);



In [72]:
yerror = rand(50)
errorbar(x, y1, yerror)


Out[72]:
<Container object of 3 artists>

In [73]:
data = rand(100)
boxplot(data);



In [74]:
import matplotlib.image as image
img = image.imread('./auxFiles/logo.png')
imshow(img)


Out[74]:
<matplotlib.image.AxesImage at 0x7faa81617d30>

Cool tricks and magics!


In [99]:
from IPython.display import HTML
HTML('<iframe src=http://www.unimelb.edu.au width=700 height=350></iframe>')


Out[99]:

In [ ]:
from IPython.display import Image
Image("./auxFiles/logo.png")

In [ ]:
from IPython.display import YouTubeVideo
YouTubeVideo('HW29067qVWk')

In [100]:
# %load https://matplotlib.org/_downloads/unicode_minus.py

In [109]:
?

In [ ]:
%time